package com.ktjiaoyu.crm.repository;

import com.ktjiaoyu.crm.entity.Chance;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author lee
 * 逻辑处理层---销售机会管理
 */
public interface ChanceRepository extends JpaRepository<Chance, Long>, JpaSpecificationExecutor<Chance> {
    @Query(value = "update sal_chance " +
            "set chc_source=:#{#chance.chcSource}," +
            "chc_cust_name=:#{#chance.chcCustName},chc_title=:#{#chance.chcTitle}," +
            "chc_rate=:#{#chance.chcRate},chc_linkman=:#{#chance.chcLinkman}," +
            "chc_tel=:#{#chance.chcTel},chc_desc=:#{#chance.chcDesc} " +
            "where chc_id=:#{#chance.chcId}", nativeQuery = true)
    @Modifying
    @Transactional(timeout = 10)
    public void edit(Chance chance);

    @Query(value = "update sal_chance set  chc_status=:#{#chcStatus} where chc_id=:#{#chcId}", nativeQuery = true)
    @Modifying
    @Transactional(timeout = 10)
    public void updateChcStatusByChcId(String chcStatus, Long chcId);
}
